local xushi = fk.CreateSkill{
  name = "lingling__xushi",
  tags = { Skill.Switch },
}

Fk:loadTranslationTable{
  ["lingling__xushi"] = "虚实",
  [":lingling__xushi"] = "转换技，出牌阶段开始和结束时，你可以使用一张①基本牌②普通锦囊牌，然后视为使用一张①普通锦囊牌②基本牌。",

  [":lingling__xushi_yang"] = "转换技，出牌阶段开始和结束时，你可以使用一张<font color=\"#E0DB2F\">①基本牌</font>②普通锦囊牌，"..
  "然后视为使用一张<font color=\"#E0DB2F\">①普通锦囊牌</font>②基本牌。",
  [":lingling__xushi_yin"] = "转换技，出牌阶段开始和结束时，你可以使用一张①基本牌<font color=\"#E0DB2F\">②普通锦囊牌</font>，"..
  "然后视为使用一张①普通锦囊牌<font color=\"#E0DB2F\">②基本牌</font>。",

  ["#lingling__xushi_yang-invoke"] = "虚实：你可以使用一张基本牌，然后视为使用一张普通锦囊牌",
  ["#lingling__xushi_yin-invoke"] = "虚实：你可以使用一张普通锦囊牌，然后视为使用一张基本牌",
  ["#lingling__jizhan_yang-use"] = "虚实：你可以视为使用一张普通锦囊牌",
  ["#lingling__jizhan_yin-use"] = "虚实：你可以视为使用一张基本牌",
}

local spec = {
  anim_type = "switch",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(xushi.name) and player.phase == Player.Play
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local pattern, prompt = ".|.|.|.|.|basic", "#lingling__xushi_yang-invoke"
    if player:getSwitchSkillState(xushi.name, false) == fk.SwitchYin then
      pattern, prompt = ".|.|.|.|.|normal_trick", "#lingling__xushi_yin-invoke"
    end
    local use = room:askToPlayCard(player, {
      skill_name = xushi.name,
      pattern = pattern,
      prompt = prompt,
      cancelable = true,
      extra_data = {
        bypass_times = true,
        extraUse = true,
      },
      skip = true,
    })
    if use then
      use.extraUse = true
      event:setCostData(self, {extra_data = use})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local use = table.simpleClone(event:getCostData(self).extra_data)
    room:useCard(use)
    if not player.dead then
      local pattern, prompt = "normal_trick", "#lingling__jizhan_yang-use"
      if player:getSwitchSkillState(xushi.name, true) == fk.SwitchYin then
        pattern, prompt = "basic", "#lingling__jizhan_yin-use"
      end
      local names = pattern == "basic" and Fk:getAllCardNames("b") or Fk:getAllCardNames("t")
      use = room:askToUseVirtualCard(player, {
        name = names,
        skill_name = xushi.name,
        prompt = prompt,
        cancelable = true,
        extra_data = {
          bypass_times = true,
          extraUse = true,
        },
      })
    end
  end,
}
xushi:addEffect(fk.EventPhaseStart, spec)
xushi:addEffect(fk.EventPhaseEnd, spec)

return xushi
